<template>
  <el-dialog v-model="centerDialogVisibleFlag" title="提醒" style="width: 500px;" @close="closeDialog">
    <div class="dialog_content_box">
      <el-icon>
        <WarningFilled />
      </el-icon>
      <p>确认要删除此条打卡记录吗？</p>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="centerDialogVisibleFlag = false, delId = ''">取消</el-button>
        <el-button type="primary" @click="deleteApp" :disabled="flagTime > 0">
          <span v-if="flagTime > 0">{{ flagTime }}s </span> 确认
        </el-button>
      </div>
    </template>
  </el-dialog>

  <addBaseTeacherClockIn ref="addBaseTeacherClockIn" />

  <!-- <el-container style="min-height: calc(100vh - 70px);"> -->
  <el-main>
    <div class="teacher">
      <div class="app-table">
        <div class="app-body">
          <div class="app-search">
            <el-form :inline="true" class="demo-form-inline" v-model="form">
              <el-form-item label="人员姓名">
                <el-input placeholder="请输入人员姓名" v-model="form.name" @keyup.enter="searchEnter"></el-input>
              </el-form-item>
              <el-form-item label="人员工号">
                <el-input placeholder="请输入人员工号" v-model="form.teacherNumber" @keyup.enter="searchEnter"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button class="serach_btn" type="primary" plain @click="onSubmit">搜索</el-button>
                <el-button class="add_btn" type="success" plain @click="add">添加</el-button>
              </el-form-item>
            </el-form>
          </div>
          <el-table :data="list" size="default" style="width: 100%;" :row-class-name="tableRowClassName">
            <el-table-column prop="id" label="序号" width="100" />
            <el-table-column prop="teacherName" label="人员姓名" />
            <el-table-column prop="teacherNumber" label="人员工号" />
            <el-table-column prop="submitDate" label="打卡时间" style="width:200px;" />

            <el-table-column label="打卡方式" width="130px">
              <template #default="scope">
                <span v-if="scope.row.code == 41 || scope.row.code == 31">出门</span>
                <span v-if="scope.row.code == 21 || scope.row.code == 11">进门</span>
                <span v-if="!['41', '31', '21', '11'].includes(scope.row.code)">会议考勤</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="100px">
              <template #default="scope">
                <el-button class="del_btn" @click="delHandle(scope.row)">删除</el-button>
              </template>
            </el-table-column>

            <template v-slot:empty>
              <el-empty description="暂无数据"></el-empty>
            </template>
          </el-table>
          <el-config-provider :locale="locale">
            <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
              layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
              @current-change="changeCurrentPage">
            </el-pagination>
          </el-config-provider>
        </div>
        <bottomView />
      </div>
    </div>
  </el-main>
  <!-- </el-container> -->
</template>

<script>

import addBaseTeacherClockIn from "@/components/baseInfo/addBaseTeacherClockIn.vue";

import bottomView from "@/components/bottom.vue";
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { Picture as IconPicture, WarningFilled } from "@element-plus/icons-vue";
import { getCurrentInstance } from "vue";
import { decrypt, formatTime1 } from "@/utils/dateFormat";


export default {
  name: "BaseTeacherList",

  data() {
    return {
      type: 0,
      title: "",
      page: 1,
      pageSize: 10,
      total: 0,
      limit: 10,
      list: [],
      flagId: '',
      schoolNames: [],
      user: {},
      flagTime: 10,
      delId: "",
      centerDialogVisibleFlag: false,
      form: {
        name: "",
        teacherNumber: "",
      },
      selectData: {},
      mobileNumber: '',
    };
  },
  components: {
    addBaseTeacherClockIn,
    IconPicture,
    ElConfigProvider,
    ElMessageBox,
    ElMessage,
    bottomView, WarningFilled,
  },

  setup() {
    // const instance = getCurrentInstance()
    // let schoolNames = instance.appContext.config.globalProperties.$schoolNames
    // console.log("schoolNames", schoolNames)
    return {
      locale: zhCn,
      // schoolNames: schoolNames
    }
  },
  mounted() {
    this.user = JSON.parse(sessionStorage.getItem('user'))
    this.getTemperatureReportingList();
  },
  methods: {
    searchEnter: function (e) {
      console.log(e);
      // 使用 which 和 keyCode 属性来解决兼容问题
      var keyCode = window.event ? e.keyCode : e.which;
      var val = e.target.value;
      if (keyCode == 13 && val) {
        this.getTemperatureReportingList();
      }
    },
    closeDialog() {
      this.delId = ""
      this.centerDialogVisibleFlag = false
    },
    add() {
      this.$refs.addBaseTeacherClockIn.title = "添加打卡记录"
      this.$refs.addBaseTeacherClockIn.dialogFormVisible = true
      this.$refs.addBaseTeacherClockIn.getBaseTeacherList()
      this.$refs.addBaseTeacherClockIn.user = this.user
    },
    delHandle(data) {
      this.delId = data.id
      this.flagTime = 10
      this.centerDialogVisibleFlag = true
      let timer = setInterval(() => {
        if (this.flagTime == 0) {
          clearInterval(timer)
        } else {
          this.flagTime -= 1
        }
      }, 1000)
    },
    deleteApp() {
      httpService("/javaApi/temperatureReporting/deleteById", "id=" + this.delId, "post").then(
        (data) => {
          if (data.code == 200) {
            ElMessage.success("删除成功");
            this.getTemperatureReportingList();
            this.delId = ""
            this.centerDialogVisibleFlag = false
          } else {
            ElMessage.error("删除失败");
          }
        }
      );
    },


    onSubmit() {
      this.getTemperatureReportingList();
    },
    // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
    changePageSize(size) {
      this.pageSize = size;
      this.limit = size;

      this.getTemperatureReportingList();
    },

    // 改变页码，page：回调参数，表示当前选中的“页码”
    changeCurrentPage(page) {
      this.page = page;
      this.getTemperatureReportingList();
    },
    tableRowClassName({ row, rowIndex }) {
      return "";
    },
    getTemperatureReportingList() {
      // + "/" + this.user.campus
      httpService(
        "/javaApi/temperatureReporting/listAll/" + this.page + "/" + this.pageSize,
        {
          teacherName: this.form.name,
          teacherNumber: this.form.teacherNumber,
        },
        "get"
      ).then((data) => {
        this.list = data.list;
        this.total = data.total;
      });
    },

  },
};
</script>

<style scoped>
.el-main {
  padding: 0px;
  text-align: left
}

.teacher-content {
  width: 100%;
}

.app-table {
  background: #eff3f5;
  padding: 5px 10px 10px;
}

.app-separator {
  padding-top: 10px;
  padding-bottom: 20px;
  padding-left: 10px;
}

.app-body {
  background: white;
  padding: 20px 20px 10px 20px;
  margin-bottom: 10px;
  min-height: calc(100vh - 204px);
}

.el-table .warning-row {
  --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
  --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
  text-align: center;
  margin-top: 10px;
}

.serach_btn {
  background-color: #007EFF;
  color: #fff;
  border-radius: 8px;
  border: none;
}

.add_btn {
  background-color: #00c78c;
  color: #fff;
  border-radius: 8px;
  border: none;
}

.edit_btn {
  background-color: #fff;
  color: #00c78c;
  border: none;
}

.del_btn {
  background-color: #fff;
  color: #FF0000;
  border: none;
}

.dialog_content_box {
  display: flex;
  align-items: center;
}

.dialog_content_box .el-icon {
  color: rgb(230, 162, 60);
  font-size: 24px;
  margin-right: 15px;
}
</style>
